﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;

namespace DotNetStar.TheKing.Services
{
    public class PasswordHasher
    {
        public static string GeneratePasswordSalt() => Guid.NewGuid().ToString().Replace("-", string.Empty).ToUpper();

        public static string GeneratePassword(string password, string passwordSalt)
        {
            string hashedStr = $"{password}{passwordSalt}";
            var hashedData = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(hashedStr));

            return BitConverter.ToString(hashedData).Replace("-", string.Empty);
        }

        public static bool VelidatePassword(string password, string passwordSalt, string hashedPassword)
            => GeneratePassword(password, passwordSalt) == hashedPassword;
    }
}
